﻿using System;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Maps.MapControl;

namespace MyFloridaHouse.SilverlightOpenDistricts
{
    public delegate void AddressCorrectionEventHandler(object sender, AddressCorrectionEventArgs e);

    public class AddressCorrectionEventArgs : EventArgs
    {
        public AddressCorrectionEventArgs(int iAddressID, double iLat, double iLon, int iLayerID, int iRegionID)
        {
            this.addressID = iAddressID;
            this.lat = iLat;
            this.lon = iLon;
            this.layerID = iLayerID;
            this.regionID = iRegionID;
        }
        public readonly int addressID;
        public readonly double lat;
        public readonly double lon;
        public readonly int layerID;
        public readonly int regionID;
    }

    public partial class xAddressLocationCorrection : Canvas
    {
        public Location location = new Location();
        public int addressID;
        public int layerID;
        public int regionID;

        public xAddressLocationCorrection()
        {
            InitializeComponent();
        }

        // Event we are publishing for other objects to subscribe to
        public static event AddressCorrectionEventHandler AddressCorrection;


        // The method which fires the Event
        protected void SendAddressCorrection(object sender, AddressCorrectionEventArgs addressCorrectionArgs)
        {
            // Check if there are any Subscribers
            if (AddressCorrection != null)
            {
                // Call the Event
                AddressCorrection(sender, addressCorrectionArgs);
            }
        }

        private void btnOK_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
            AddressCorrectionEventArgs args = new AddressCorrectionEventArgs(addressID, location.Latitude, location.Longitude, layerID, regionID);
            SendAddressCorrection(this, args);
        }

        private void btnCancel_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }
    }
}
